/**
 * @file lv_appmenu.h
 *
 */

#ifndef LV_APPMENU_H
#define LV_APPMENU_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/
#include "lvgl.h"
#include "../appicon/lv_appicon.h"
#include "../../widgets/lv_obj_matrix/lv_obj_matrix.h"

/*********************
 *      DEFINES
 *********************/
/*struct _lv_appmenu_info_t cfg define*/
#define LV_APPMENU_KEY_LOOP  (1 << 7) /*at the end, loop back to the front*/
#define LV_APPMENU_LINE_LOOP (1 << 6) /*left and right keys limited within the same line*/

/**********************
 *      TYPEDEFS
 **********************/

struct _lv_appmenu_t;
struct _lv_appmenu_info_t{
  /*global info*/
  const char *bg_image_path;
  int16_t appicon_count; /*>0:Vertical growth; <0:Horizontal growth*/
  /*app icon matrix_info*/
  lv_align_t matrix_align;
  uint8_t cfg;
  lv_obj_matrix_margin_t matrix_margin;
  lv_obj_matrix_cell_size_t matrix_cellsize;
  /*appicon info*/
  lv_appicon_cfg_t appicon_cfg;
  const lv_appicon_info_t  *appicon_info_ary;
  /*enter app callback function*/
  void (*enter_app_cb)(struct _lv_appmenu_t *appmenu, uint32_t info_ary_id, uint32_t app_id);
};
typedef struct _lv_appmenu_info_t lv_appmenu_info_t;

struct _lv_appmenu_t{
    lv_obj_t * obj_bg;
    lv_obj_t * obj_matrix;
    const lv_appmenu_info_t *info;
    const uint16_t *appicon_lut;  /*AppIcon lookup table, with the first digit being the number*/
    uint16_t hfocus;
    uint16_t vfocus;
 };
 typedef struct _lv_appmenu_t lv_appmenu_t;

/**********************
 * GLOBAL PROTOTYPES
 **********************/

/**
 * app icon create, create icons and icon characters, Configure click callback
 * @param appmenu      uninitialized lv_appmenu_t
 * @param parent    pointer to an object
 * @param info      app intrinsic information
 * @param appicon_lut configuration information in the current system
 * @return          void
 */
void lv_appmenu_create(lv_appmenu_t *appmenu, lv_obj_t * parent, const lv_appmenu_info_t *info, const uint16_t *appicon_lut);

/**
 * Set the focus position, which can be used for restoring after reloading
 * @param appmenu   initialized lv_appmenu_t
 * @param hfocus    Horizontal focus icon position
 * @param vfocus    Vertical focus icon position
 * @return          void
 */
void lv_appmenu_set_focus(lv_appmenu_t *appmenu, uint16_t hfocus, uint16_t vfocus);

/**
 * rebuild bg image，call when the background image changes
 * @param appmenu   initialized lv_appmenu_t
 * @return          void
 */
void lv_appmenu_rebuild_bg(lv_appmenu_t *appmenu);

/**
 * rebuild bg app icon, when icon and icon lookup table change
 * @param appmenu   initialized lv_appmenu_t
 * @return          void
 */
void lv_appmenu_rebuild_appicon(lv_appmenu_t *appmenu);

/**
 * delete appmenu
 * @param appmenu   initialized lv_appmenu_t
 * @return          void
 */
void lv_appmenu_delete(lv_appmenu_t *appmenu);

/**
 * get the focus position, which can be used for restoring after reloading
 * @param appmenu   initialized lv_appmenu_t
 * @return          Horizontal focus icon position
 */
uint16_t lv_appmenu_get_hfocus(const lv_appmenu_t *appmenu);

/**
 * get the focus position, which can be used for restoring after reloading
 * @param appmenu   initialized lv_appmenu_t
 * @return          Vertical focus icon position
 */
uint16_t lv_appmenu_get_vfocus(const lv_appmenu_t *appmenu);

/**********************
 *      MACROS
 **********************/

#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /*LV_APPMENU_H*/
